﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DTO;

namespace FastDeal.Admin
{
    public partial class QuanLyNhanXet : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["DaDangNhap"] == null || (bool)Session["DaDangNhap"] == false)
            {
                Response.Redirect("~/Default.aspx");
            }
            if ((int)Session["LoaiThanhVien"] != 1)
            {
                Response.Redirect("~/Default.aspx");
            }

            if (!IsPostBack)
            {
                LoadDanhSachNhanXet();
            }
        }

        /// <summary>
        /// Load danh sách nhận xét
        /// </summary>
        private void LoadDanhSachNhanXet()
        {
            NhanXet_BUS db = new NhanXet_BUS();
            List<NhanXet> list = new List<NhanXet>();
            list = db.LayDanhSach_NhanXet();
            gvDanhSachNhanXet.DataSource = list;
            gvDanhSachNhanXet.DataBind();
            int i=0;
            //int batdau = gvDanhSachNhanXet.PageIndex*3;

            foreach(NhanXet dr in list)
            {
                //if (i >= batdau && i <= batdau + 2)
                //{
                    //lấy username:
                    TaiKhoan_BUS db2 = new TaiKhoan_BUS();
                    TaiKhoan tk = db2.LayThongTin_TaiKhoan(dr.UserID);
                    ((HyperLink)(gvDanhSachNhanXet.Rows[i].Cells[1].FindControl("lbUsername"))).Text = tk.UserName;
                    ((Label)(gvDanhSachNhanXet.Rows[i].Cells[1].FindControl("lbNhanXet"))).Text = dr.NoiDung;
                //}
               
                i++;
            }

            //if (Panel1.Height.Value < 800)
            //{
            //    Panel1.Height = 800;
            //}
        }

        protected void gvDanhSachNhanXet_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //lấy mã nhận xét
            NhanXet_BUS db = new NhanXet_BUS();
            NhanXet nx = new NhanXet();
            nx.MaNhanXet = int.Parse(((Label)gvDanhSachNhanXet.Rows[e.RowIndex].Cells[0].FindControl("lbMa")).Text);
            db.Xoa_NhanXet(nx);
            LoadDanhSachNhanXet();
        }

        protected void gvDanhSachNhanXet_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
        //    gvDanhSachNhanXet.PageIndex = e.NewPageIndex;
        //    LoadDanhSachNhanXet();
        }
    }
}